package com.arofoxmsn.repository.location;

import java.util.List;

import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;

import com.arofoxmsn.model.location.Location;
import com.arofoxmsn.repository.BaseTable;

public class LocationTable extends BaseTable<Location>{
	
	private static double RANGE_LAT = 0.1;
	private static double RANGE_LONG = 0.1;
	
	@Override
	protected Class getModelClass() {
		return Location.class;
	}
	
	/**
	 * this method return all locations that could be possible to be near
	 * @param location
	 * @return
	 */
	public List<Location> retrieveCandidates(Location location){
		double latPlustTop = location.getLat()+RANGE_LAT;
		double latFloor = location.getLat()-RANGE_LAT;
		double longTop = location.getLon()+RANGE_LONG;
		double longFloor = location.getLon()-RANGE_LONG;
		
		Criterion criterionLatitud = Restrictions.between("lat", latFloor, latPlustTop);
		Criterion criterionLongitud = Restrictions.between("lon", longFloor, longTop);
		Criterion andRestrictino = Restrictions.and(criterionLatitud, criterionLongitud);
		return retrieveAll(andRestrictino);
	}
	
}